<template>
	<view :class="currentTheme">
		<a-nabbar :name="title" />
		<view class="u-padding-32">
			<view class="u-margin-bottom-50">
				<view class="u-margin-bottom-30 box-title u-font-32">{{isStore ? '上传门店LOGO': '上传发行LOGO'}}</view>
				<uploader ref="image" :max-count="1"  :bgColor="currentThemeObj.backgroundSecondColor"  :list="form.image"
					@getImgStr="getImgStr" 
					@uploaded="getUpload" />
					
				<view class="u-margin-bottom-30 box-title u-font-32 u-margin-top-20">上传{{isStore ? '门店' : '发行'}}营业执照</view>
				<uploader ref="image" :max-count="1" :bgColor="currentThemeObj.backgroundSecondColor" :list="form.businessLicense"
					@getImgStr="getbusinessLicenseStr" 
					@uploaded="getUpload" />
					
				<template v-if="isStore">
					<view class="u-margin-bottom-30 box-title u-font-32 u-margin-top-20">上传门头照(最多可上传六张)</view>
					<uploader ref="image" :max-count="6" :bgColor="currentThemeObj.backgroundSecondColor" :list="form.storeImage"
						@getImgStr="getstoreImageStr" 
						@uploaded="getUpload" />
				</template>
			</view>
			<itemBox paddinglr="40">
					<label-box :label="`${isStore ? '门店' : '发行'}名`" labelSize="32" labelWidth="130">
						<u-input v-model="form.nickname" :clearable="false" border 
						:placeholder="`请输入${isStore ? '门店' : '发行'}名`"
						:borderColor="currentThemeObj.inputBorderColor" 
						 :placeholder-style="`color:${currentThemeObj.placeholderColor}`"/>
					</label-box>
					<label-box label="联系电话" labelSize="32" labelWidth="130">
						<u-input v-model="form.contactNumber" type="number" 
						:clearable="false" border :borderColor="currentThemeObj.inputBorderColor" placeholder="请输入联系电话" :placeholder-style="`color:${currentThemeObj.placeholderColor}`"/>
					</label-box>
					<label-box label="微信号" labelSize="32" labelWidth="130">
						<u-input v-model="form.wxId" :clearable="false" border :borderColor="currentThemeObj.inputBorderColor" placeholder="请输入微信号" :placeholder-style="`color:${currentThemeObj.placeholderColor}`"/>
					</label-box>
					<label-box label="所在城市" labelSize="32" labelWidth="130">
						<select-item v-model="form.address" :list="cityList" mode="popSelectCity"  @getSelect="getSelectCity"></select-item>
					</label-box>
					<label-box label="详细地址" labelSize="32" labelWidth="130">
						<u-input v-model="form.detailAddress" :clearable="false" border :borderColor="currentThemeObj.inputBorderColor" placeholder="请输入详细地址" :placeholder-style="`color:${currentThemeObj.placeholderColor}`"/>
					</label-box>
			</itemBox>
		</view>
		<fixed-team btnText="提交" @btnClick="setInfo"></fixed-team>
	</view>
</template>

<script>
	
	import selectCityMixins from '@/mixins/selectMixins.js'
	import uploader from '@/components/upload/upload.vue'
	import {add} from '@/api/crud.js'
	export default {
		mixins:[selectCityMixins],
		components: {
			uploader
		},
		computed: {
			title() {
				return this.option.label
			},
			isStore(){
				return this.option.authType==3
			}
		},
		data() {
			return {
				option:{},
				form:{
					"nickname": "",
					"contactNumber": "",
					"wechatNumber": "",
					"cityId": "",
					"cityName": "",
					"cityPath": "",
					"address": "",
					"image": "",
					cityTxt:'',
					businessLicense:'',
					storeImage:''
				},
				uploadFlag:true
			};
		},
		onLoad(option) {
			this.option = option;
			this.form = {...this.form,...this.loginForm}
			const cityPath = this.form.cityPath;
			if(cityPath) this.$set(this.form,'address',this.cityPathFormat(cityPath))
		},
		methods: {
			//上传的图片
			getImgStr(str){
				this.form.image = str;
			},
			//上传的图片
			getbusinessLicenseStr(str){
				this.form.businessLicense = str;
			},
			//上传的图片
			getstoreImageStr(str){
				this.form.storeImage = str;
			},
			//监听上传图片
			getUpload(flag){
				this.uploadFlag = flag;
			},
			setInfo(){
				if(!this.uploadFlag) {
					this.$u.toast('图片上传中')
					return false;
				}
				const {wxId,nickname,contactNumber,address,detailAddress,image,businessLicense,storeImage} = this.form;
				if(!wxId){
					this.$u.toast('微信号码不能为空')
					return false;
				}
				if(!contactNumber){
					this.$u.toast('手机号码不能为空')
					return false;
				}
				if(contactNumber&&!this.$u.test.mobile(contactNumber)){
					this.$u.toast('手机号码不正确')
					return false;
				}
				if(!nickname){
					this.$u.toast('姓名不能为空')
					return false;
				}
				if(!address){
					this.$u.toast('请选择所在城市')
					return false;
				}
				if(!detailAddress){
					this.$u.toast('详细地址不能为空')
					return false;
				}
				if(!image){
					this.$u.toast('LOGO不能为空')
					return false;
				}
				if(!storeImage&&this.isStore){
					this.$u.toast('门头照不能为空')
					return false;
				}
				if(!businessLicense){
					this.$u.toast('营业执照不能为空')
					return false;
				}
				console.log(image,businessLicense,storeImage)
				this.loading = true;
				this.form.userId = this.loginForm.uid
				this.form.type = this.option.authType
				add(this.form,'user','systemApi','grant').then(res=>{
					this.loading = false;
					this.$store.dispatch('getInfo');
					this.routeBack('提交成功')
				}).catch(()=>{
					this.loading = false;
				})
			},
		},
	}
</script>